--[[/**
-- * 
* 戴莉技能3 叫鸡buff 通过这个buff让敌人变成鸡 [0]秒内 被 [1]或[1]以上敌人伤害时 随机将其中一名敌人变鸡 [2] 变鸡buffid
-- *
-- */]]

---@class BuffEffect225100 : BaseBuffEffect
BuffEffect225100 = ClientFight.CreateClass("BuffEffect225100", ClientFight.BaseBuffEffect)
local t = BuffEffect225100
t.Buff_Effect_225100 = "Buff_Effect_225100";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local skill = parameters[2];
    local fightResult = parameters[3];
    local attacker = parameters[1];
    if not AttackUtils.isDamage(fightResult.state) then
        return IBuffEffect.FAIL;
    end
    --if (skill.getSkill().getSkillBean().getF_SkillType() != SkillTypeEnum.NORMAL_ATTACK.getId()) then
    --    return IBuffEffect.FAIL;
    --end
    if (attacker:isDie()) then
        return IBuffEffect.FAIL;
    end

    local attackers = buff.effectParams[t.Buff_Effect_225100];
    if (attackers == nil) then
        attackers = {};
        buff.effectParams[t.Buff_Effect_225100] = attackers;
    end

    local diffFrame = buff.buffBean.f_BuffEffectValue[1] / Global.FIGHT_FRAME; -- 时间差
    local amount = buff.buffBean.f_BuffEffectValue[2]; -- 人数
    local addBuffModelId = buff.buffBean.f_BuffEffectValue[3]; -- 变鸡buff

    for k, entry in pairsByKeys(attackers) do
        local attackFrame = entry;
        if (fight.frame - attackFrame > diffFrame) then
            attackers = {}
        end
    end

    attackers[attacker.fighterId] = fight.frame;

    if (table.getn(attackers) < amount) then
        return IBuffEffect.FAIL;
    end

    -- 在时间段内超过配表人数给我造成了伤害 触发成功 随机给其中一个人叫个鸡
    local list = Table_Rand(getKeysTable(clone(attackers)));
    for k, fid in pairs(list) do
        local fighter = fight.getFighter(fid);
        if (fighter ~= nil and not fighter:isDie()) then
            BuffManager.addBuff(fight, buff.skill, buff.source, fighter, false, addBuffModelId, 1);
            return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
        end
    end
    attackers = {};
    return IBuffEffect.FAIL;

end

t.New()